<?php
namespace My\Model;

use Think\Model;

class UserModel extends Model {
	
	protected $_validate = array(
			array('name','require','会员登录名(手机号)必须',self::MUST_VALIDATE),
			array('name','','登录名(手机号)已经存在',self::EXISTS_VALIDATE, 'unique'),
			array('password', 'require', '密码必须', self::MUST_VALIDATE, '', self::MODEL_INSERT),
			array('email','','管理员Email已经存在',self::EXISTS_VALIDATE, 'unique'),
			array('email','email','管理员Email格式不正确',self::EXISTS_VALIDATE),
	);
	
	protected $_auto = array(
			array('password', 'hash_pwd', self::MODEL_BOTH, 'function'),
			array('last_login_time', 'time', self::MODEL_UPDATE, 'function'),
			array('last_login_ip', 'get_client_ip', self::MODEL_UPDATE, 'function'),
	);
	
	protected function _before_update(&$data, &$options) {
		$password = I('password', '');
		if(empty($password)) unset($data['password']);
		parent::_before_update($data, $options);
	}
	
}